package com.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.domain.User;
import com.service.Impl.UsersServiceImpl;
import com.service.UsersService;

@WebServlet("/updateServlet")
public class UpdateServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
        //获取域中登录用户名
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("username");
        //获取登录用户名信息
        UsersService usersService = new UsersServiceImpl();
        User user = usersService.findByName(name);
        //获取输入框数据
        String username = request.getParameter("username");//获取输入的原密码
        //判断密码是否正确
        response.setContentType("text/html;charset=utf-8");
        if(!user.getPassword().equals(username)) {
            //不相等发送反馈信息
            response.getWriter().write("<font style='color:red'> 输入原密码密码错误~</font>");
            return;
        }else {
            //相等发送反馈信息
            response.getWriter().write("<font style='color:green'> 密码正确~</font>");
            return;
        }


    }
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
}
